package com.yc.zyz.servlet;

import com.google.gson.Gson;
import com.yc.mybatis.damai.MyBatisHelper;
import com.yc.zyz.entity.Task;
import com.yc.zyz.mapper.TaskMapper;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Company 源辰信息
 *
 * @author navy
 * @date 2024/7/28
 * Email haijunzhou@hnit.edu.cn
 */
@WebServlet("/findTask")
public class FindTaskServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        SqlSession session = MyBatisHelper.getSession();
        TaskMapper taskMapper = session.getMapper(TaskMapper.class);
        Task tasks = taskMapper.findById(id);
        Gson gson = new Gson();
        String json = gson.toJson(tasks);
        resp.setContentType("application/json;charset=utf-8");
        resp.getWriter().println(json);
        session.close();
    }
}
